import Cookies from 'js-cookie'
import {removeToken} from "@/utils/auth";


const state = {
    goodsList: []
}

const getters = {
    getGoodsList(){
        return state.goodsList;
    }
}

const mutations = {
    ADD_FOOD(state,data){
        const food = state.goodsList.filter(i => i.goodsId === data.goodsId)[0];
        console.log(data);
        if (food===undefined){
            state.goodsList.push(data);
        }else {
            food.number = data.number;
        }
        console.log(state.goodsList)
    },
    CLEAR_GOODLIST(state){
        state.goodsList = [];
    }
}

const actions = {
    addFood({commit},data){
        commit("ADD_FOOD",data)
    },
    clearFood({commit}){
        commit("CLEAR_GOODLIST")
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}